package com.cuit.zuke.product.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.cuit.zuke.product.mapper.GoodsMapper;
import com.cuit.zuke.product.model.entity.Goods;
import com.cuit.zuke.product.model.vo.GoodsExVO;

public class GoodsListener extends AnalysisEventListener<GoodsExVO> {

    private GoodsMapper goodsMapper;

    public GoodsListener(GoodsMapper goodsMapper){
        this.goodsMapper = goodsMapper;
    }

    @Override
    public void invoke(GoodsExVO goodsExVO, AnalysisContext analysisContext) {
        // GoodsEeVo -> Goods
        //调用方法添加到数据库
        Goods goods = new Goods();
        goods.setGoodsId(goodsExVO.getGoodsId());
        goods.setGoodsName(goodsExVO.getGoodsName());
        goods.setGoodsPrice(goodsExVO.getGoodsPrice());
        goods.setGoodsDescript(goodsExVO.getGoodsDescript());
        goods.setGoodsImage(goodsExVO.getGoodsImage());

        goods.setGoodsStatus((byte)0);
        String goodsType = goodsExVO.getGoodsType();
        if (goodsType.equals("零食")){
            goods.setGoodsType(1);
        }else if (goodsType.equals("地方特产")){
            goods.setGoodsType(2);
        }else {
            goods.setGoodsType(3);
        }
        goodsMapper.insert(goods);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
